﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TowerMagicGenerator : MonoBehaviour {
    public GameObject MagicPrefab;
    public Tower tower;
    public Timer timer;
    public float GenerateTime;
    public AbstractMagicCard TrackingMagic;
    public Renderer CoolDownPrograssBar;

    private void Awake()
    {
        timer = new Timer(GenerateTime);
    }

    void Update ()
    {
        CoolDownPrograssBar.material.SetFloat("_Prograss", timer.currentTime / GenerateTime);

        if (TrackingMagic != null) return;
        if(tower.TowerOwner==PlayerType.Player)
        {
            if(timer.Tick(Time.deltaTime))
            {
                var g = Instantiate(MagicPrefab, transform.position, transform.rotation);
                TrackingMagic = g.GetComponent<FallMagicCard  >();
                TrackingMagic.CardOwner = PlayerType.Player;
            }
        }
        else
        {
            timer.Reset();
        }

		
	}
}
